﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using BlueHarvestSnippetGenerator.TutorialClasses.TutorialController;
using DataContextLayer;
using ICSharpCode.AvalonEdit;

namespace BlueHarvestSnippetGenerator.Pages
{
    /// <summary>
    /// Interaction logic for C_Sharp_If_Conditional.xaml
    /// </summary>
    public partial class TutorialPage : Page
    {

        TutorialControl tutorialController;

        public TutorialPage()
        {
            InitializeComponent();
            NavigationCommands.BrowseBack.InputGestures.Clear();
            //component_Bar1.Testi.Content = "C# If Conditional";

            tutorialController = new TutorialControl(this);

            //Added LMC
            _testSteps = TutorialControl.TutorialSteps.Start;

            TutorialDisplay.Options.InheritWordWrapIndentation = true;

            
        }

        


        #region "Lou Testing Changes"


        

        TutorialControl.TutorialSteps _testSteps;
        private int _stepCounter = 0;
        bool _hasAnswer;

        private Section _nonCode;
        private Run _runString;
        private String _tutorialOutput;


        public string UserAnswerText
        {
            get
            {
                string tempString = "";

                var temp = textEditor.Text.ToCharArray();
                foreach (char c in temp)
                {
                    if (!string.IsNullOrWhiteSpace(c.ToString(CultureInfo.InvariantCulture)))
                    {
                        tempString += c.ToString(CultureInfo.InvariantCulture);
                    }
                }

                return tempString;
            }
            
        }

        public TextEditor DisplayTutorialText
        {
            get { return TutorialDisplay; }
            set { TutorialDisplay = value; }
        }
            
       


        private void ChangeStep()
        {
            
           
            switch (_testSteps)
            {

                case TutorialControl.TutorialSteps.Start:


                    //TutorialDisplay.AppendText(tutorialGen.TutorialTitle + " : " + tutorialGen.TutorialAuthor + " \n ");
                    //TutorialDisplay.AppendText(tutorialGen.StepsFor[0]+" \n "+tutorialGen.AnswersFor[0]);
                    //tutorialGen.testMethod();
                    btnNextStep.Content = "Go On";

                    _testSteps = TutorialControl.TutorialSteps.Next;

                    break;

                case TutorialControl.TutorialSteps.Completed:
                  

                   

                    btnNextStep.Content = "Completed";

                    //_hasAnswer = false;

                    break;
                case TutorialControl.TutorialSteps.Current:

                    

                    btnNextStep.Content = "Go On";

                    //_hasAnswer = false;

                    

                    _testSteps = TutorialControl.TutorialSteps.Next;

                    break;
                case TutorialControl.TutorialSteps.Previous:

                    //_stepCounter--;

                    //if (_stepCounter < 0)
                    //{
                    //    _stepCounter = 0;
                    //}

                    _testSteps = TutorialControl.TutorialSteps.Current;

                    //part1.Blocks.Clear();

                    ChangeStep();

                    break;
                case TutorialControl.TutorialSteps.Next:

                    //if (_hasAnswer)
                    //{
                    //    //MessageBox.Show(AnswerCheck(UserAnswerText).ToString());
                    //}

                    _stepCounter++;

                    //if (_stepCounter == _stepsList.Count-1)
                    //{
                    //    part1.Blocks.Clear();

                    //    _testSteps = TutorialControl.TutorialSteps.Completed;

                    //    ChangeStep();

                    //    break;
                    //}
                    
                    //part1.Blocks.Clear();

                    _testSteps = TutorialControl.TutorialSteps.Current;

                    ChangeStep();

                    break;
                case TutorialControl.TutorialSteps.Error:

                    MessageBox.Show("ERROR");

                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            
        }

        #endregion
        


       
        //the button click handles the entire process of moving to next step
        private void BtnNextStepClick(object sender, RoutedEventArgs e)
        {
            
            TutorialDisplay.Clear();
            tutorialController.Stepper();
            

        }

        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            TutorialDisplay.Clear();
            tutorialController.FinisehdTutorial();
            
        }

        
    }
}
